package logic

import (
	"class/models"
	"context"

	"class/classrpc/classrpc"
	"class/classrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CourseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCourseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CourseListLogic {
	return &CourseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 课程列表
func (l *CourseListLogic) CourseList(in *classrpc.CourseListRequest) (*classrpc.CourseListResponse, error) {
	// todo: add your logic here and delete this line

	var course []models.Course

	models.DB.Debug().Find(&course)

	var courses []*classrpc.CourseList
	for _, cours := range course {
		list := classrpc.CourseList{
			Title:     cours.Title,
			TeacherId: int64(cours.TeacherId),
			Category:  cours.Category,
			Price:     float32(cours.Price),
			Image:     cours.Image,
			Info:      cours.Info,
		}
		courses = append(courses, &list)
	}

	return &classrpc.CourseListResponse{
		List: courses,
	}, nil
}
